Leecode 239. Sliding Window Maximum
Given an array nums, there is a sliding window of size k which is moving from the very left of the array to the very right. You can only see the k numbers in the window. Each time the sliding window moves right by one position. Return the max sliding window.
作法
def maxSlidingWindow(self, nums: List[int], k: int) -> List[int]:
if len(nums) == 0: return []
max_value = max(nums[:k])
res = [max_value]
for i in range(len(nums)-k):
if nums[i+k] > max_value:
max_value = nums[i+k]
elif nums[i] == max_value:
max_value = max(nums[i+1:i+k+1])
res.append(max_value)
return res